package jmbeas.kata.price;

import java.util.ArrayList;
import java.util.List;

public class ShoppingCart {
	
	List<Entry> entries = new ArrayList<Entry>();

	public void add(Item anItem) {
		// TODO Si hay ya una entrada para este item, aumentar la cantidad
		Entry entry = new Entry(1,anItem);
		entries.add(entry);
	}

	/**
	 * Calcula el valor total de la cesta.
	 * 
	 * @return
	 */
	public Money getTotal() {
		Money total = new Money(0,"EUR");
		for( Entry entry : entries ) {
			Price price = entry.getItem().getPrice();
			Money entryValue = new Money(entry.getQuantity() * price.getValue().getAmount(),"EUR"); 
			total.add(entryValue);
		}
		return total;
	}

}

class Entry {
	private int quantity;
	private Item item;
	// Price price;
	
	public Entry(int quantity, Item item) {
		this.quantity = quantity;
		this.item = item;
	}

	public int getQuantity() {
		return quantity;
	}

	public Item getItem() {
		return item;
	}
	
	
}